The
storage account provides an entry point to the Queue service via the
Queue service endpoint URI. At the account level of the hierarchy, the
Queue service supports only one operation: List Queues. The URI of a
specific account is of the format <account
name>.queue.core.windows.net. Table 1 describes the List Queues operation, and Table 2 lists some important characteristics of the List Queues function.
Table 1. Queue Account Operation
Operation | Description |
---|
List Queues | This
operation gets the list of all the queues in a storage account. You can
limit the number of records returned by specifying a filter on queue
names and the size of the data set in the request. Table 5-4 lists all the possible URI parameters for this operation. |
Table 2. Queue Account Operations Characterstics
Operation | HTTP Verb | Cloud URI | Development Storage URI | HTTP Version | Permissions |
---|
List Queues | GET | account name>.queue.core.windows.net?comp=list | http://127.0.0.1:10001/<devstorageaccount>?comp=list | HTTP/1.1 | Only the account owner can call this operation. |
<account name> is the storage account name, such as proazurestorage; and <devstorageaccount>
is the account name for the development storage. The HTTP verb used in
this operation is GET. The table lists the URI format for accessing the
cloud Queue service as well as the development storage URI. Port 10001
is the default Queue service port in the development fabric.
The URI for the List Queues operation supports additional optional parameters, as listed in Table 3.
The sample REST request for List Queues in raw format looks like Listing 1.
Example 1. List Queues REST Request
GET /?comp=list&prefix=test&maxresults=50&timeout=30 HTTP/1.1 x-ms-date: Wed, 27 May 2009 04:33:00 GMT Authorization: SharedKey proazurestorage:GCvS8cv4Em6rWMuCVix9YCsxVgssOW62S2U8zjbIa1w= Host: proazurestorage.queue.core.windows.net Connection: Keep-Alive
|
The characteristics of the REST request in Listing 5-4 are as follows:
The parameter comp=list at the account level of the Queue service yields the list of all the queues.
The prefix=test filters the results by queue names starting with "test".
The maxresults=50 returns 50 queues or less.
The x-ms-date is the UTC timestamp of the request.
The Authorization header contains the SharedKey of the request.
The Host header points to the Queue service in the cloud.
Because the request is
sending a maxresults parameter, it makes sense to keep the HTTP
connection alive because it's highly likely that the user will retrieve
the next set of results by making another call to the Queue service.
Listing 2 shows the response for the List Queues request.
Example 2. List Queues REST Response
HTTP/1.1 200 OK Content-Type: application/xml Server: Queue Service Version 1.0 Microsoft-HTTPAPI/2.0 x-ms-request-id: dde8c8bd-121d-4692-a578-d8fac08e4525 Date: Wed, 17 Jun 2009 01:24:45 GMT Content-Length: 648
<?xml version="1.0" encoding="utf-8"?> <EnumerationResults AccountName="http://proazurestorage.queue.core.windows.net/"> <Prefix>test</Prefix> <MaxResults>50</MaxResults> <Queues> <Queue> <QueueName>testq</QueueName> <Url>http://proazurestorage.queue.core.windows.net/testq</Url> </Queue> <Queue> <QueueName>testq1</QueueName> <Url>http://proazurestorage.queue.core.windows.net/testq1</Url> </Queue> <Queue> <QueueName>testq2</QueueName> <Url>http://proazurestorage.queue.core.windows.net/testq2</Url> </Queue> <Queue> <QueueName>testq3</QueueName> <Url>http://proazurestorage.queue.core.windows.net/testq3</Url> </Queue> </Queues> <NextMarker /> </EnumerationResults>
|
In Listing 2,
the header consists of the HTTP status (200 OK) indicating the success
of the operation. The response body is in XML format with
<EnumerationResults /> as the root element. The <Queues />
element contains the retrieved queues. The Queue element encompasses
queue attributes like the queue name and the queue URI. An empty
<NextMarker /> element indicates that all the results have been
retrieved.
To help you understand
the Queue service programming model, open the Windows Azure Storage
Operations project from Ch4Solution.sln. The project consists of a
Windows form and uses the StorageClient project from the same solution
for making calls to all the Windows Azure storage. The StorageClient
project is shipped with the Windows Azure SDK. I also created a helper
class named WindowsAzureStorageHelper in the ProAzureCommonLib project
for wrapping the StorageClient methods. Figure 1
shows the user interface for the Windows Azure Storage Operations
application as it pertains to the Operations account of the Queue
service.
In Figure 1,
the top Account section displays the account name and SharedKey of the
storage account. When the Windows Azure Storage Operations.exe
application starts, it loads the account information from the
configuration file. Listing 3 shows the account configuration in the project's app.config file.
Example 3. App.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key ="AccountName" value="proazurestorage"/> <add key ="AccountSharedKey" value="RyyGrNJ4z5tViRWKR3QOJAK"/> <add key="BlobStorageEndpoint" value="http://blob.core.windows.net"/> <add key="QueueStorageEndpoint" value="http://queue.core.windows.net"/> <add key="TableStorageEndpoint" value="http://table.core.windows.net"/> <add key="LocalStorageAccountName" value="devstoreaccount1"/> </appSettings> </configuration>
|
The AccountName and
AccountSharedKey values are loaded when the application starts and
displays these values in the Account and Key text fields, respectively.
When you start the application, make sure to enter the account name and
shared key of your storage account. The QueueStorageEndpoint is the URI
of the Queue service.
The WindowsAzureStorageHelper class in ProAzureCommonLib project has a ListQueue() method for retrieving queue names. Listing 4 shows the code for ListQueues() method.
Example 4. ListQueues() Method
public IEnumerable<MessageQueue> ListQueues(string prefix) { if (string.IsNullOrEmpty(prefix))
{ return this.QueueStorageType.ListQueues(); } else { return this.QueueStorageType.ListQueues(prefix); } }
|
In Listing 5-7,
the ListQueues() method calls the ListQueues() method on the
QueueStorageType object, which is of type QueueStorage from the
StorageClient assembly. In the QueueStorage class, there are two
overloaded ListQueues() methods. The first one returns all the queues
in an account, whereas the second one accepts a prefix as a filter term
for filtering the queues by names. Figure 2 illustrate the execution of the ListQueues operation in the Windows Azure Storage Operations application.
When you click the List
Queues button, the application retrieves queues from the Queue service
and displays the names of queues in the Queues ListBox. In the
parameter section, you can specify the prefix.
Figure 3 is a sequence diagram for the ListQueues() method.
In Figure 3, the Windows Azure Storage Operations application calls the ListQueues() method on the WindowsAzureStorageHelper object in the ProAzureCommonLib assembly. The helper object then calls the ListQueues()
method on the QueueStorage and QueueStorageRest objects. QueueStorage
is an abstract class, and QueueStorageRest inherits and implements the
abstract methods from QueueStorage. The ListQueues() method in turn calls the private method ListQueuesImpl(). Finally, the actual logic for making the HTTP request to the Queue service is in the ListQueuesImpl()
method. The Queue service returns the list of queues in an HTTP
response, which is parsed and propagated back to the Windows Azure
Storage Operations application for display.